package com.daiziru.config;


import com.daiziru.common.constant.Constants;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义mvc控制器
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    Constants consts;

    @Bean
    ModelMapper modelMapper() {
        return new ModelMapper();
    }

    /**
     * 重写，标记新的静态文件，这样子才可以读取到
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/avatar/**")
                .addResourceLocations("file:///" + consts.getUploadDir() + "/avatar/");
    }

}
